package com.fenghuajueli.idiomppp.ui.fragment.allidiom;


import android.content.Intent;
import android.os.Bundle;

import android.widget.GridView;

import com.fenghuajueli.idiomppp.R;
import com.fenghuajueli.idiomppp.adapter.AllIdiomGridAdapter;
import com.fenghuajueli.idiomppp.config.BizCallBack;
import com.fenghuajueli.idiomppp.entity.VideoInfoEntity;
import com.fenghuajueli.libbasecoreui.listener.OnListClickListener;
import com.fenghuajueli.libbasecoreui.mvp.LifecycleBaseFragment;

import java.util.List;


/**
 * 成语大全界面
 */
public class AllStoryFragment extends LifecycleBaseFragment<AllStoryPresenter> implements AllStoryView {

    GridView idiomGridView;
    AllIdiomGridAdapter allIdiomGridAdapter;

    public static BizCallBack mBiz;

    @Override
    public AllStoryPresenter initPresenter() {
        return new AllStoryPresenter(getActivity());
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        idiomGridView = (GridView) findViewById(R.id.idiomGridView);

    }

    @Override
    protected void firstLoadData() {
        presenter.loadData();
    }

    @Override
    public int getContentViewId() {
        return R.layout.fragment_all_story;
    }


    public static AllStoryFragment newInstance() {
        Bundle args = new Bundle();
        AllStoryFragment fragment = new AllStoryFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void dataLoadSuccess(List<VideoInfoEntity> videoInfoEntities) {
        allIdiomGridAdapter = new AllIdiomGridAdapter(getActivity(), videoInfoEntities);
        allIdiomGridAdapter.setOnListClickListener(new OnListClickListener<VideoInfoEntity>() {
            @Override
            public void itemClick(int position, VideoInfoEntity data) {
                if(mBiz!=null){
                    if(mBiz.onBiz(position)){
                       //跳视频
                    }
                }else {
                    //跳视频
                }
            }
        });
        idiomGridView.setAdapter(allIdiomGridAdapter);
    }
}
